#include "MlpNetwork.h"

namespace fullsail_ai {

	void MlpNetwork::initialize(int (*numberGenerator)(), std::size_t inputCount,
	                            std::size_t hiddenNeuronCount, std::size_t actionCount)
	{
		// TODO: 2
		// Initialize the hidden layer, then the output layer.
		hiddenLayer.initialize(inputCount,hiddenNeuronCount,numberGenerator);	
		outputLayer.initialize(hiddenNeuronCount,actionCount,numberGenerator);
		
	}

	void MlpNetwork::generateOutputs(std::vector<double> const& inputs,
	                                 std::vector<double>& outputs) const
	{
		// TODO: 8
		// Generate the outputs of the network by running the inputs through
		// the appropriate layers.
		std::vector<double> tInputs;
		hiddenLayer.feedForward(inputs,tInputs);
		outputLayer.feedForward(tInputs,outputs);

	}

	void MlpNetwork::computeOutputErrors(std::vector<double> const& expectedOutputs,
	                                     std::vector<double> const& actualOutputs,
	                                     std::vector<double>& outputErrors)
	{
		// TODO: 10
		// Compute the error between each expected output and the corresponding actual output.
		for(unsigned i = 0; i < expectedOutputs.size();i++)
		{
			outputErrors[i] = (expectedOutputs[i] - actualOutputs[i])*actualOutputs[i]*(1-actualOutputs[i]);
		}
	}

	void MlpNetwork::learnTrainingSets(std::vector<std::vector<double> > const& trainingSetInputs,
	                                   std::vector<std::vector<double> > const& expectedOutputs,
	                                   double learningFactor)
	{
		// TODO: 13
		// Train the network using the provided training set inputs and expected outputs.
	}
}  // namespace fullsail_ai

